package com.springboot.demo.common.customValidator;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Component;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;

/**
 * @author wubc683
 * @desc
 * @date 2021-09-14 15:56
 */
@Component
public class ListNotHasNullClass implements ConstraintValidator<ListNotHasNull, List> {

    @Override
    public void initialize(ListNotHasNull listNotHasNull) {
    }

    @Override
    public boolean isValid(List target, ConstraintValidatorContext context) {
        if (target == null) {
            return true;
        }
        for (Object o : target) {
            if (o == null) {
                return false;
            }
        }
        return true;
    }
}
